package com.base.controller;

import com.base.entity.DictItemEntity;
import com.base.service.DictItemService;
import com.base.utils.PageUtils;
import com.base.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2020-12-11 16:12:32
 */
@RestController
@RequestMapping("sys/dictitem")
@Api(tags = "字典列表")
public class DictItemController {
    @Autowired
    private DictItemService dictItemService;

    /**
     * 列表
     */
    @ApiOperation(value = "字典item表list", response = DictItemEntity.class)
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = dictItemService.getDictItemList(params);

        return Result.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") String id) {
        DictItemEntity dictItem = dictItemService.getById(id);

        return Result.success(dictItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody DictItemEntity dictItem) {
        dictItemService.saveDictItem(dictItem);

        return Result.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody DictItemEntity dictItem) {
        dictItemService.saveOrUpdateDictItem(dictItem);

        return Result.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody String[] ids) {
        dictItemService.removeByIds(Arrays.asList(ids));

        return Result.success();
    }

}
